package com.mall.dubbo.api;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mall.dubbo.mapper.PmsProductMapper;
import com.mall.model.domain.PmsProduct;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author xyiaao
 * @description 针对表【pms_product(商品信息)】的数据库操作Api实现
 * @createDate 2022-03-29 19:46:09
 */
@DubboService
public class PmsProductApiImpl extends ServiceImpl<PmsProductMapper, PmsProduct>
        implements PmsProductApi {

    @Autowired
    private PmsProductMapper pmsProductMapper;

    @Autowired
    private PmsProductMapper productMapper;

    @Override
    public List<PmsProduct> findByIds(List<Long> ids) {

        LambdaQueryWrapper<PmsProduct> lqw = new LambdaQueryWrapper<>();
        lqw.in(CollUtil.isNotEmpty(ids), PmsProduct::getId, ids);

        return pmsProductMapper.selectList(lqw);
    }

    @Override
    public List<PmsProduct> simpleList(String keywords) {
        LambdaQueryWrapper<PmsProduct> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(PmsProduct::getName,keywords).or().like(PmsProduct::getProductSn,keywords);
        List<PmsProduct> pmsProducts = productMapper.selectList(queryWrapper);
        return pmsProducts;
    }

    @Override
    public List<PmsProduct> findByIds(Long[] ids) {
        LambdaQueryWrapper<PmsProduct> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(PmsProduct::getId,ids);
        List<PmsProduct> pmsProducts = productMapper.selectList(queryWrapper);
        return pmsProducts;
    }

    @Override
    public Page<PmsProduct> findBySomewhere(Integer pageNum, Integer pageSize,
                                            Integer brandId, Integer productCategoryId,
                                            Integer publishStatus, Integer verifyStatus,
                                            String keyword, String productSn) {
        LambdaQueryWrapper<PmsProduct> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(brandId!=null,PmsProduct::getBrandId,brandId)
                .eq(productCategoryId!=null,PmsProduct::getProductCategoryId,productCategoryId)
                .eq(publishStatus!=null,PmsProduct::getPublishStatus,publishStatus)
                .eq(verifyStatus!=null,PmsProduct::getVerifyStatus,verifyStatus)
                .like(keyword!=null,PmsProduct::getName,keyword)
                .like(productSn!=null,PmsProduct::getProductSn,productSn);
        Page<PmsProduct> page = new Page<>(pageNum,pageSize);
        Page<PmsProduct> products = productMapper.selectPage(page,queryWrapper);

        return products;
    }

    @Override
    public PmsProduct findById(Integer id) {
        PmsProduct product = productMapper.selectById(id);
        return product;
    }

    @Override
    public List<PmsProduct> findByCategoryId(Integer productCategoryId) {
        LambdaQueryWrapper<PmsProduct> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(PmsProduct::getProductCategoryId,productCategoryId);
        List<PmsProduct> products = productMapper.selectList(queryWrapper);
        return products;
    }
}




